function param = parse_args(param, args)
%% parse_args(type, args)
% parse input arguments.
narg = length(args);
count = 1;
while (count <= narg)
    arg = args{count};
    if ~ischar(arg)
        error('parseArgs:InvalidArg', 'Argument name must be a string.');
    end
    if (count + 1 > narg)
        error('parseArgs:qf:TooFewArg', 'Need one more argument.');
    end
    switch lower(arg)
        case 'threshold'
            % setting threshold
            val = args{count + 1};
            if (~isfloat(val)) || (val <= 0)
                error('parseArgs:threshold:InvalidArg','Invalid value of threshold.');
            end
            param.threshold = val;
            count = count + 2;
        case 'points'
            % setting points
            val = args{count + 1};
            switch size(val, 1)
                case 2
                    param.points = val;
                case 1
                    param.points = zigzag(val);
                otherwise
                    error('parseArgs:points:InvalidArg', 'points must be 1 or 2 rows.');
            end
            count = count + 2;
        otherwise
            % including: 
            % verbose, qf, use_abs, diff_n, diff_dis, diff_dir, pe_n, pe_func
            % use_jpegtbx, qf, space
            param.(arg) = args{count + 1};
            count = count + 2;
    end
end
end %parseArgs
